<template>
  <p-drawer
    placement="right"
    :closable="false"
    width="calc(100vw - 200px)"
    :visible="visible"
    :mask-closable="false"
    :destroy-on-close="true"
    @close="onClose"
  >
    <div v-show="addMatter">
      <div style="position: relative">
        <TaskTitle
          :icon-name="iconName"
          :title-name="titleName"
          :color="color"
        />
        <p-button
          v-show="(isEdit && isShowEdit) || (!addState && isShowEdit)"
          class="commonbutton edit"
          type="primary"
          @click="edit"
        >
          编辑
        </p-button>
      </div>
      <div class="g-drawer-list-container" style="overflow-x: hidden">
        <p-tabs
          :animated="false"
          class="tabs-container"
          default-active-key="1"
          @change="callback"
        >
          <p-tab-pane key="1" tab="基本信息">
            <div class="connect_divs">
              <AddVisitForm
                ref="form"
                :form="form"
                :is-foot="isFoot"
                :add-state="addState"
                :is-edit="isEdit"
                :delete-file-id.sync="deleteFileId"
              />
              <BottomLine v-if="isEdit" style="margin-top: 50px" />
            </div>
          </p-tab-pane>
          <p-tab-pane key="2" tab="线索">
            <div>
              <clueDetailTable
                :select-cur.sync="selectCur"
                :is-edit="isEdit"
                :cur-keys.sync="curKeys"
                :load="load"
                @add-clue="addClue"
                @delete-clue="deleteClue"
              />
            </div>
          </p-tab-pane>
          <p-tab-pane key="3" tab="商机">
            <div>
              <businessDetailTable
                :load="load"
                :select-business.sync="selectBusiness"
                :is-edit="isEdit"
                :business-keys.sync="businessKeys"
                @add-business="addBusiness"
                @delete-business="deleteBusiness"
              />
            </div>
          </p-tab-pane>
          <p-tab-pane key="4" tab="客户团队">
            <div>
              <customerTeamDetailTable
                :load="load"
                :is-edit="isEdit"
                :select-customer.sync="selectCustomer"
                :customer-keys.sync="customerKeys"
                @add-customer="addCustomer"
                @delete-customer="deleteCustomer"
              />
            </div>
          </p-tab-pane>

          <p-tab-pane key="5" tab="我方团队">
            <div>
              <myTeamDetailTable
                :is-edit="isEdit"
                :load="load"
                :select-my.sync="selectMy"
                :my-keys.sync="myKeys"
                @add-my="addMy"
                @delete-my="deleteMy"
              />
            </div>
          </p-tab-pane>
          <p-tab-pane key="6" tab="跟进事项">
            <div>
              <followMatterDetailTable
                :load="load"
                :is-edit="isEdit"
                :select-follow-matter.sync="selectFollowMatter"
                :follow-matter-keys.sync="followMatterKeys"
                @detail-matter="detailMatter"
                @refresh-follow-matter="refreshFollowMatter"
                @add-follow-matter="addFollowMatter"
              />
            </div>
          </p-tab-pane>

          <p-tab-pane key="7" tab="会议纪要">
            <div class="connect_divs">
              <meetMinute
                :is-edit="isEdit"
                :meet-detail-data="meetDetailData"
                :meet-record-data="meetRecordData"
                :load="load"
                :visit-id="visitId"
                :default-select-key="defaultSelectKey"
                :add-state="addState"
                :customer-code="customerCode"
                @meet-record-add="meetRecordAdd"
                @select-meet="selectMeet"
                @meet-record-delete="meetRecordDelete"
                @res-date="resDate"
              />
              <meetDetail
                :load-meet="loadMeet"
                :is-edit="isEdit"
                :is-show-export="isShowExport"
                :meet-detail-data.sync="meetDetailData"
                :minutes-id="minutesId"
                :is-delete.sync="isDelete"
                :is-insert.sync="isInsert"
                @import-meet="importMeet"
              />
              <BottomLine />
            </div>
          </p-tab-pane>
          <p-tab-pane key="8" tab="附件">
            <div>
              <fileTable
                :load="load"
                :is-edit="isEdit"
                :file-table-data="fileTableData"
                @up-file="upFile"
                @file-delete="fileDelete"
              />
            </div>
          </p-tab-pane>
          <p-tab-pane key="9" tab="操作日志">
            <div class="connect_divs">
              <ProgressLog :list="logList" />
              <BottomLine />
            </div>
          </p-tab-pane>
        </p-tabs>
      </div>
    </div>
    <div v-show="!addMatter">
      <div>
        <TaskTitle
          :icon-name="mattericonName"
          :title-name="matterTitleName"
          :color="matterColor"
        />
      </div>
      <div class="g-drawer-list-container" style="overflow-x: hidden">
        <TitleSecondary title="基本信息" />
        <AddMatterForm
          ref="formMatter"
          :matter-form="matterForm"
          :is-edit="isEdit"
          :state="state"
          :select-cur.sync="selectCur"
          :select-business.sync="selectBusiness"
        />
      </div>
    </div>
    <ButtonGroup
      v-show="addMatter"
      class="g-drawer-footer"
      :options="footerButtons"
      @click="handleButtonClick"
    />
    <ButtonGroup
      v-show="!addMatter"
      class="g-drawer-footer"
      :options="footerMatterButtons"
      @click="handleButtonClick"
    />
    <DialogVisitDetailBusinessList
      ref="business"
      :visit-id="visitId"
      :visible.sync="visibleBusiness"
      :select-business.sync="selectBusiness"
      :business-keys.sync="businessKeys"
      :customer-code="customerCode"
      @business-table-list="businessTableList"
    />
    <DialogVisitDetailClueList
      ref="clue"
      :visit-id="visitId"
      :customer-code="customerCode"
      :visible.sync="visibleClue"
      :select-cur.sync="selectCur"
      :cur-keys.sync="curKeys"
      @visit-cur-info="visitCurInfo"
    />
    <DialogVisitCustomerList
      ref="customer"
      :visible.sync="visibleCustomer"
      :customer-code="customerCode"
      :select-customer.sync="selectCustomer"
      :customer-keys.sync="customerKeys"
      :visit-id="visitId"
      @customer-table-list="customerTableList"
      @customer-list="customerList"
    />
    <DialogVisitMyList
      ref="my"
      :datasource-my="datasourceMy"
      :visible.sync="visibleMy"
      :select-my.sync="selectMy"
      :load="load"
      :visit-id="visitId"
      :my-keys.sync="myKeys"
      @my-table-list="myTableList"
      @my-list="myList"
    />
    <DialogAddMeetRecord
      ref="meetRecord"
      :visible.sync="visibleMeetRecord"
      @add-meet-record="addMeetRecord"
    />
    <DialogUploadMeet
      ref="upload"
      :meet-detail-data.sync="meetDetailData"
      @change="handleInsertChange"
    />
    <DialogUpvisit
      ref="uploadFile"
      :isload.sync="isload"
      type="visit"
      :file-list="fileList"
      :visit-id="visitId"
      @refresh-data="refreshData"
    />
  </p-drawer>
</template>

<script>
import ProgressLog from '@/components/task/ProgressLog.vue';
import DialogVisitDetailBusinessList from '@/components/dialog/DialogVisitDetailBusinessList.vue';
import DialogVisitCustomerList from '@/components/dialog/DialogVisitCustomerList.vue';
import DialogVisitMyList from '@/components/dialog/DialogVisitMyList.vue';
import DialogAddMeetRecord from '@/components/dialog/DialogAddMeetRecord.vue';
import DialogVisitDetailClueList from '@/components/dialog/DialogVisitDetailClueList.vue';
import DialogUploadMeet from '@/components/dialog/DialogUploadMeet.vue';
import DialogUpvisit from '@/components/dialog/DialogUpvisit.vue';
import clueDetailTable from './clueDetailTable.vue';
import meetDetail from './meetDetail.vue';
import meetMinute from './meetMinute.vue';
import AddVisitForm from './AddVisitForm.vue';
import AddMatterForm from './AddMatterForm.vue';
import fileTable from './fileTable.vue';
import customerTeamDetailTable from './customerTeamDetailTable.vue';
import myTeamDetailTable from './myTeamDetailTable.vue';
import businessDetailTable from './businessDetailTable.vue';
import followMatterDetailTable from './followMatterDetailTable.vue';
import {
  postAddVisit,
  getVisitCurInfo,
  getVisitBusinessInfo,
  getCustomerTableList,
  postCancelVisit,
  getMyList,
  getFollowMatter,
  postAddMatter,
  getMatterInfo,
  postEditMatter,
  postAddMeetRecord,
  postDeleteMeetRecord,
  postMeetRecordList,
  postMeetDetail,
  postAddMeetDetail,
  postFileTable,
  postFileDelete,
  getVisitLog,
  postDeleteCustomer,
  getDeleteInfo,
  getClueDetails,
  getVisitInfo,
} from '@/api/visit.js';
import { getCurrentUser } from '@/api/public.js';

const defaultForm = {
  id: '',
  visitNo: '',
  visitState: '',
  visitName: '',
  visitTime: '',
  visitStyle: '',
  department: '',
  customerName: '',
  customerCode: '',
  visitType: '',
  emergencyLevel: '',
  executionStatus: '',
  address: '',
  remark: '',
  createUserName: '',
  updateTime: '',
  updateUserName: '',
  createTime: '',
  updateUserDepartmentName: '',
  createUserDepartmentName: '',
  leadsList: [],
  opportunityList: [],
  logList: [],
};
const defaultMatterForm = {
  id: '',
  state: '0',
  tel: '',
  visitNo: '',
  leadsName: '',
  processId: undefined,
  leadsNo: '',
  opportunityNo: '',
  opportunityName: '',
  topic: '',
  currentUserName: '',
  createDepartmentName: '',
  currentUser: [],
  currentUserId: '',
  currentDepartmentName: '',
  currentDepartmentCode: '',
  remark: '',
};
export default {
  components: {
    DialogVisitDetailBusinessList,
    DialogVisitDetailClueList,
    AddVisitForm,
    clueDetailTable,
    customerTeamDetailTable,
    businessDetailTable,
    DialogVisitCustomerList,
    myTeamDetailTable,
    DialogVisitMyList,
    followMatterDetailTable,
    AddMatterForm,
    meetMinute,
    meetDetail,
    DialogAddMeetRecord,
    DialogUploadMeet,
    fileTable,
    DialogUpvisit,
    ProgressLog,
  },
  // mixins: [DrawerMixin],
  props: {
    isCancelVisit: {
      type: Boolean,
      default: false,
    },
    visible: {
      type: Boolean,
      default: false,
    },
    addState: {
      type: Boolean,
      default: false,
    },
    detail: {
      type: Object,
      default: () => ({}),
    },
    isFoot: {
      type: Boolean,
      default: false,
    },
    titleInfo: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      matterForm: {
        ...defaultMatterForm,
      },
      form: {
        ...defaultForm,
      },
      isload: false,
      saveType: 1,
      matterTitleName: '事项详情',
      mattericonName: 'Det',
      titleName: '拜访详情',
      color: 'green',
      matterColor: 'green',
      iconName: 'Det',
      planIdNew: undefined,
      saleList: [],
      isEdit: false,
      currentUser: '',
      createDepartmentName: '',
      isSave: false,
      deleteFileId: [],
      visibleClue: false,
      addMatter: true,
      visibleBusiness: false,
      visibleMeetRecord: false,
      visibleCustomer: false,
      visibleMy: false,

      selectCur: [],
      curKeys: [],
      selectBusiness: [],
      selectCustomer: [],
      selectMy: [],
      businessKeys: [],
      customerKeys: [],
      datasourceMy: [],
      myKeys: [],
      selectFollowMatter: [],
      followMatterKeys: [],
      meetRecordData: [],
      meetDetailData: [],
      fileList: [],
      fileTableData: [],
      visitId: '',
      defaultSelectKey: [],
      saveNumber: '1',
      minutesId: '',
      logList: [],
      load: false,
      loadMeet: false,
      customerCode: '',
      state: '0',
      isDelete: false,
      isInsert: false,
    };
  },

  computed: {
    isShowEdit() {
      return this.detail.visitState === '3' ? false : true;
    },
    isShowExport() {
      const res = this.meetRecordData.length ? false : true;
      return res;
    },
    footerMatterButtons() {
      console.log('11111', this.state);
      const buttons =
        this.addState && this.state === '0'
          ? [
              {
                key: 'saveMatter',
                type: 'primary',
                label: '保存',
                auth: true,
              },
              {
                key: 'closeMatter',
                label: '返回',
              },
            ]
          : [
              {
                key: 'closeMatter',
                label: '返回',
              },
            ];
      return buttons;
    },
    footerButtons() {
      const buttons = this.addState
        ? this.saveNumber === '1' || this.saveNumber === '7'
          ? [
              {
                key: 'save',
                type: 'primary',
                label: '保存',
                auth: true,
              },
              {
                key: 'close',
                label: '返回',
              },
            ]
          : [
              {
                key: 'close',
                label: '返回',
              },
            ]
        : [
            {
              key: 'close',
              label: '返回',
            },
          ];
      if (this.isCancelVisit && !this.addState) {
        buttons.unshift({
          key: 'cancelVisit',
          label: '取消拜访',
        });
      }
      return buttons;
    },
  },
  watch: {
    visible: {
      handler(val) {
        if (!val) return;
        if (!this.addState) {
          const plan = this.detail || {};
          this.isEdit = true;
          this.visitId = plan.visitNo;
          this.customerCode = plan.customerCode;
          this.form = {
            id: plan.id || '',
            visitNo: plan.visitNo || '',
            visitName: plan.visitName || '',
            // salesGroupCode: plan.createUserGroup,
            // salesGroupCode:plan.salesGroupCode||'',
            visitTime: plan.visitTime || '',
            visitState: plan.visitState || '',
            visitStyle: plan.visitStyle || '',
            department: plan.department || '',
            customerName: plan.customerName || '',
            customerCode: plan.customerCode || '',
            visitType: plan.visitType || '',
            remark: plan.remark || '',
            emergencyLevel: plan.emergencyLevel || '',
            executionStatus: plan.executionStatus || '',
            address: plan.address || '',
            createUserName: plan.createUserName || '',
            updateTime: plan.updateTime || '',
            updateUserName: plan.updateUserName || '',
            createTime: plan.createTime || '',
            updateUserDepartmentName: plan.updateUserDepartmentName || '',
            createUserDepartmentName: plan.createUserDepartmentName || '',
          };
        }
      },
      immediate: true,
    },

    titleInfo: {
      handler(val) {
        this.titleName = val.titleName;
        this.color = val.color;
        this.iconName = val.iconName;
      },
      deep: true,
    },
  },
  created() {
    this.getCurrentInfo();
  },
  methods: {
    async visitBaseInfo() {
      const result = await getVisitInfo(this.visitId);
      const detail = result?.data?.data || {};
      this.form = {
        id: detail.id || '',
        visitNo: detail.visitNo || '',
        visitName: detail.visitName || '',
        // salesGroupCode: plan.createUserGroup,
        // salesGroupCode:plan.salesGroupCode||'',
        visitTime: detail.visitTime || '',
        visitState: detail.visitState || '',
        visitStyle: detail.visitStyle || '',
        department: detail.department || '',
        customerName: detail.customerName || '',
        customerCode: detail.customerCode || '',
        visitType: detail.visitType || '',
        remark: detail.remark || '',
        emergencyLevel: detail.emergencyLevel || '',
        executionStatus: detail.executionStatus || '',
        address: detail.address || '',
        createUserName: detail.createUserName || '',
        updateTime: detail.updateTime || '',
        updateUserName: detail.updateUserName || '',
        createTime: detail.createTime || '',
        updateUserDepartmentName: detail.updateUserDepartmentName || '',
        createUserDepartmentName: detail.createUserDepartmentName || '',
      };
    },
    resDate() {
      this.isDelete = false;
      this.isInsert = false;
    },
    async curTableList() {},
    async deleteClue(val) {
      const params = {
        idList: val.join(','),
        type: 'L',
        visitNo: this.visitId,
      };
      const result = await getDeleteInfo(params);
      if (result.data.code === 0) {
        this.$message.success('删除成功');
        this.visitCurInfo();
      }
    },
    async deleteBusiness(val) {
      const params = {
        idList: val.join(','),
        type: 'O',
        visitNo: this.visitId,
      };
      const result = await getDeleteInfo(params);
      if (result.data.code === 0) {
        this.$message.success('删除成功');
        this.businessTableList();
      }
    },
    async deleteCustomer(val) {
      const result = await postDeleteCustomer(val, 0, this.visitId);
      if (result.data.code === 0) {
        this.$message.success('删除成功');
        this.customerTableList();
      }
    },
    async deleteMy(val) {
      const result = await postDeleteCustomer(val, 1, this.visitId);
      if (result.data.code === 0) {
        this.$message.success('删除成功');
        this.myTableList();
      }
    },
    async fileDelete(val) {
      const result = await postFileDelete(val, this.visitId);
      if (result.data.code === 0) {
        this.$message.success('删除成功');
        this.fileTableList();
      }
    },
    async fileTableList() {
      const data = { bizType: 'visit', bizId: this.visitId };
      this.load = true;
      const result = await postFileTable(data).finally(() => {
        this.load = false;
      });
      this.fileTableData = result.data.data;
    },
    refreshData() {
      this.fileTableList();
    },
    async checkData() {
      const addData = this.meetDetailData.filter(
        (item) => item?.id || ''.toString().indexOf('_meet') !== -1
      );
      console.log('addData: ', addData);
      const index = addData.findIndex((item) => {
        console.log('item.topic : ', item.topic);
        return !item.topic || !item.content;
      });
      console.log('index: ', index);
      if (index > -1) {
        this.$message.error('请填写新增会议纪要明细的必填项');
        return false;
      }
      return true;
    },
    importMeet() {
      this.$refs.upload?.uploader();
    },
    upFile() {
      this.$refs.uploadFile?.uploader();
    },
    async selectMeet(val) {
      this.minutesId = val[0];
      this.loadMeet = true;
      const result = await postMeetDetail({ minutesId: val[0] }).finally(() => {
        this.loadMeet = false;
      });
      this.meetDetailData = result?.data?.data || [];
    },
    async meetRecordDelete(val) {
      const result = await postDeleteMeetRecord(val, this.visitId);
      this.resDate();
      this.meetRecordList();
    },
    async meetRecordList() {
      const data = { visitNo: this.form.visitNo };
      this.load = true;
      const result = await postMeetRecordList(data).finally(() => {
        this.load = false;
      });
      this.meetRecordData = result?.data?.data || [];
      this.defaultSelectKey = [result?.data?.data[0]?.id || ''];
    },
    async addMeetRecord() {
      const data = {
        name: this.$refs.meetRecord.form.meetName,
        visitNo: this.form.visitNo,
      };
      const result = await postAddMeetRecord(data);
      if (result.data.code === 0) {
        this.$message.success('新增会议成功');
        this.meetRecordList();
        this.resDate();
      }
    },
    async visitCurInfo() {
      const params = { visitNo: this.form.visitNo || '' };
      this.load = true;
      const result = await getVisitCurInfo(params).finally(
        () => (this.load = false)
      );
      this.selectCur = result?.data?.data || [];
      this.curKeys = this.selectCur.reduce((pre, cur) => {
        pre.push(cur.id);
        return pre;
      }, []);
    },
    meetRecordAdd() {
      this.visibleMeetRecord = true;
    },
    async detailMatter(val) {
      this.saveType = 2;
      const id = val.id;
      this.addMatter = false;
      const result = await getMatterInfo(id);
      const data = result?.data?.data;
      this.state = data.state;
      if (!this.isEdit) {
        this.matterTitleName = this.state === '0' ? '编辑事项' : '事项详情';
        this.mattericonName = this.state === '0' ? 'Edit' : 'Det';
        this.matterColor = this.state === '0' ? 'blue' : 'green';
      }
      this.matterForm = {
        id: data.id,
        state: data.state,
        tel: data.tel,
        visitNo: data.visitNo,
        leadsName: data.leadsName,
        processId: data.processId,
        leadsNo: data.leadsNo,
        opportunityNo: data.opportunityNo,
        opportunityName: data.opportunityName,
        topic: data.topic,
        currentUserName: data.currentUserName,
        currentUser: [{ key: data.currentUserId, label: data.currentUserName }],
        currentUserId: data.currentUserId,
        currentDepartmentName: data.currentDepartmentName,
        currentDepartmentCode: data.currentDepartmentCode,
        remark: data.remark,
      };
    },
    async callback(key) {
      this.saveNumber = key;
      const params = { visitNo: this.form.visitNo || '' };
      console.log('params: ', params);
      if (key === '1') {
        this.visitBaseInfo();
      } else if (key === '2') {
        this.visitCurInfo();
      } else if (key === '3') {
        this.businessTableList();
      } else if (key === '4') {
        this.customerTableList();
      } else if (key === '5') {
        this.myTableList();
      } else if (key === '6') {
        this.load = true;
        const result = await getFollowMatter(params).finally(() => {
          this.load = false;
        });
        this.selectFollowMatter = result?.data?.data || [];
      } else if (key === '7') {
        this.meetRecordList();
      } else if (key === '8') {
        this.fileTableList();
      } else if (key === '9') {
        const result = await getVisitLog(params);
        this.logList = result?.data?.data;
      }
    },
    async businessTableList() {
      const params = { visitNo: this.form.visitNo || '' };
      this.load = true;
      const result = await getVisitBusinessInfo(params).finally(() => {
        this.load = false;
      });
      this.selectBusiness = result?.data?.data || [];
      this.businessKeys = this.selectBusiness.reduce((pre, cur) => {
        pre.push(cur.id);
        return pre;
      }, []);
    },
    async customerTableList() {
      const data = { visitNo: this.visitId || '', type: '0' };
      this.load = true;
      const result = await getCustomerTableList(data).finally(() => {
        this.load = false;
      });
      this.selectCustomer = result?.data?.data || [];
      this.customerKeys = this.selectCustomer.reduce((pre, cur) => {
        pre.push(cur.contactId);
        return pre;
      }, []);
    },
    async myTableList() {
      const data = { visitNo: this.visitId || '', type: '1' };
      this.load = true;
      const result = await getCustomerTableList(data).finally(() => {
        this.load = false;
      });
      this.selectMy = result?.data?.data || [];
      this.myKeys = this.selectMy.reduce((pre, cur) => {
        pre.push(cur.userId);
        return pre;
      }, []);
    },
    async addFollowMatter() {
      this.saveType = 1;
      this.matterForm = { ...defaultMatterForm };
      const params = { visitNo: this.form.visitNo || '' };
      const result = await getVisitCurInfo(params);
      this.selectCur = result?.data?.data || [];
      const res = await getVisitBusinessInfo(params);
      this.selectBusiness = res?.data?.data || [];
      this.addMatter = false;
      this.matterTitleName = '新增事项';
      this.mattericonName = 'New';
      this.matterColor = 'red';
    },
    async addCustomer() {
      this.visibleCustomer = true;
    },
    myList() {
      this.getMyList();
    },
    async getMyList() {
      const form = this.$refs.my.form;
      this.load = true;
      const result = await getMyList({
        orgCode: '',
        isDeepSearch: false,
        isSearchNonOrg: false,
        tenantId: 'geek',
        status: 1,
        pageNo: 1,
        limit: 500,
        ...form,
      }).finally(() => (this.load = false));
      this.datasourceMy = result?.data?.data?.records || [];
    },
    async addMy() {
      this.visibleMy = true;
      this.getMyList();
    },

    async addClue() {
      this.visibleClue = true;
    },
    async addBusiness() {
      this.visibleBusiness = true;
    },
    deletDusiness() {
      console.log('我是删除');
    },
    async edit() {
      this.titleName = '编辑拜访';
      this.color = 'blue';
      this.iconName = 'Edit';
      this.isSave = true;
      this.$emit('update:addState', true);
      this.isEdit = false;
    },
    async getCurrentInfo() {
      const result = await getCurrentUser();
      this.currentUser = result?.data?.data?.name || '';
      this.createDepartmentName = result?.data?.data?.departmentName || '';
      this.createDepartmentName = this.removalSame(this.createDepartmentName);
    },
    removalSame(obj) {
      obj = obj.replace(/\s*/g, '');
      const array = obj.split(',');
      console.log('array: ', array);
      const departmentName = [...new Set(array)].join(',');
      return departmentName;
    },
    clearList() {
      this.saleList = [];
    },
    async refreshFollowMatter() {
      const params = { visitNo: this.form.visitNo || '' };
      this.load = true;
      const result = await getFollowMatter(params).finally(() => {
        this.load = false;
      });
      this.selectFollowMatter = result?.data?.data || [];
    },
    onClose() {
      this.titleName = '拜访详情';
      this.color = 'green';
      this.iconName = 'Det';
      this.form = { ...defaultForm };
      this.isEdit = false;
      this.deleteFileId = [];
      this.addMatter = true;
      this.$emit('update:isFoot', false);
      this.$emit('update:visible', false);
      this.$emit('update:isCancelVisit', false);
      this.$emit('fresh');
    },
    closeMatterCallback() {
      this.state = '0';
      this.addMatter = true;
      this.titleName = '拜访详情';
      this.color = 'green';
      this.iconName = 'Det';
    },
    onClose1() {
      this.state = '0';
      this.addMatter = true;
      this.refreshFollowMatter();
      this.matterForm = {
        ...defaultMatterForm,
      };
      this.saveType = 1;
      this.titleName = '拜访详情';
      this.color = 'green';
      this.iconName = 'Det';
    },
    async saveMatterCallback() {
      const valid = await this.$refs.formMatter.validate();
      if (!valid) return new Promise(() => {});
      const data = this.$refs.formMatter.matterForm;
      data.currentUserName = data.currentUser[0].label;
      data.currentUserId = data.currentUser[0].key;

      if (this.saveType === 1) {
        data.visitNo = this.form.visitNo;
        data.createDepartmentName = this.createDepartmentName;
        const result = await postAddMatter(data);
        if (result.data.code === 0) {
          this.$message.success('新增事项成功');
          this.refreshFollowMatter();
          this.onClose1();
        }
      } else {
        const result = await postEditMatter(data);
        if (result.data.code === 0) {
          this.$message.success('修改成功');
          this.refreshFollowMatter();
          this.onClose1();
        }
      }
      console.log('????????????');
    },
    async saveCallback() {
      const formInfo = JSON.parse(JSON.stringify(this.$refs.form.form));
      formInfo.updateUserDepartmentName = this.createDepartmentName || '';
      formInfo.updateUserName = this.currentUser || '';
      if (this.saveNumber === '1') {
        const valid = await this.$refs.form.validate();
        if (!valid) return new Promise(() => {});
        const result = await postAddVisit(formInfo);
        if (result.data.code === 0) {
          this.$message.success('保存成功！');
          this.closeCallback();
          this.isSave = false;
        }
      } else if (this.saveNumber === '7') {
        const isValid = await this.checkData();
        if (!isValid) return new Promise(() => {});
        this.meetDetailData.forEach((item) => {
          item.id = '';
          item.minutesId = this.minutesId;
          if (item.id.toString().indexOf('_meet') !== -1) {
            item.id = '';
          }
        });
        this.loadMeet = true;
        const result = await postAddMeetDetail(
          this.meetDetailData,
          this.minutesId,
          this.isDelete,
          this.isInsert
        ).finally(() => {
          this.loadMeet = false;
          // this.isDelet = false;
          // this.isInsert = false;
        });
        if (result.data.code === 0) {
          this.$message.success('保存成功！');
          const result = await postMeetDetail({ minutesId: this.minutesId });
          this.meetDetailData = result?.data?.data || [];
        }
      }
    },
    async cancelVisitCallback() {
      const data = [this.detail.id];
      try {
        await this.$confirm('是否取消当前拜访');
        const result = await postCancelVisit(data);
        console.log('result: ', result);
        if (result.data.code === 0) {
          this.$message.success('取消拜访成功');
          this.onClose();
        }
      } catch (error) {
        // console.log('error: ', error);
      }
    },
    businessAddCallback() {
      this.visibleVisit = true;
    },
    closeCallback() {
      this.onClose();
    },
    handleButtonClick(key) {
      const fn = `${key}Callback`;
      this[fn] && this[fn]();
    },
  },
};
</script>
<style lang="less" scoped>
.edit {
  position: absolute;
  top: 10px;
  right: 30px;
}
.table-list-container {
  margin-top: 20px;
  height: 390px !important;
}
.connect_divs {
  height: calc(100vh - 190px);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
</style>


